<script setup>
import { ref, watch } from 'vue';

const emit = defineEmits(['allTodo', 'notTodo', 'doneTodo','deleteDoneTodo', 'deleteAllTodo'])
let state=ref('all')

const allTodo = () => {
    emit('allTodo')
    state.value= 'all'
}
const notTodo = () => {
    emit('notTodo')
    state.value= 'not'
}
const doneTodo = () => {
    emit('doneTodo')
    state.value= 'done'
}
const deleteDoneTodo = () => {
    emit('deleteDoneTodo')
    state.value= 'all'
}
const deleteAllTodo = () => {
    emit('deleteAllTodo')
    state.value= 'all'
}
watch(state, (newVal, oldVal) => {
    console.log(newVal, oldVal)
})
</script> 
<template>
    <div class="footer">
        <img src="../assets/images/OIP-C.jpg" alt="">
        <div class="line">
            <h2>
                <slot name="done"></slot>
            </h2>
            <h2>
                <slot name="all"> </slot>
            </h2>
        </div>
        <div class="btn-group">
            <button @click="allTodo" >全部</button>
            <button  v-show="state=='all'" @click="deleteAllTodo">删除全部</button>
            <button @click="notTodo" >未完成</button>
            <button @click="doneTodo" v-show="!(state=='done')">已完成</button>
            <button v-show="state=='done'" @click="deleteDoneTodo">删除已完成</button>
        </div>
    </div>
</template>
<style scoped>
.footer {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-evenly;
    align-items: center;
    background-color: #f5f5f5;
    padding: 20px;
    border-top: 1px solid #ccc;
}

.btn-group {
    display: flex;
    justify-content: space-between;
    width: 250px;
}

.btn-group button {
    padding: 10px;
    border: none;
    background-color: #fff;
    cursor: pointer;
}

.btn-group button:hover {
    background-color: #ccc;
}

.line {

    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-left: 20px;
}

h2 {
    font-size: 20px;
    font-weight: bold;
    margin: 0;
}

img {

    width: 100px;
    height: 100px;
}
</style>